home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Source Code / C / Code Resources / Simple LDEF 1.0 / Simple LDEF.c next >
Encoding:
C/C++ Source or Header  |  1996-02-07  |  3.2 KB  |  132 lines  |  [TEXT/CWIE]

  1. /*----------------------------------------------------------------------------
  2.  
  3.     File:            Simple LDEF.c
  4.  
  5.     Function:        LDEF to display text-only lists.
  6.                     
  7.     Author(s):        Erik C. Thauvin (ravensys@eskimo.com)
  8.  
  9.     Copyright:        Copyright (C) 1996 Erik C. Thauvin
  10.                     All Rights Reserved.
  11.  
  12.     Source:            Based on Steve Falkenburg's SICN LDEF
  13.  
  14.     Notes:            If the cell's data is too long, it is truncated
  15.                     and an ellipsis is added to it; the textface is
  16.                     not automatically condensed.
  17.  
  18.     Version(s):
  19.  
  20.         02/08/96    1.0        
  21.  
  22.  
  23.     History:
  24.  
  25.         02/07/96    ECT        Initial coding.
  26.         
  27.     
  28.     Disclaimer:
  29.  
  30.         This software is provided  "as is"  without  express  or implied 
  31.         warranties.  Permission is  granted  to use,  copy,  modify  and 
  32.         distribute this software, provided this disclaimer and copyright
  33.         are preserved on all copies.  This software may not, however, be
  34.         sold or distributed for  profit, or included with other software
  35.         which is sold or distributed for profit,  without the permission
  36.         of the author.
  37.  
  38. ----------------------------------------------------------------------------*/
  39.  
  40.  
  41. /* constants for spacing */
  42.  
  43. const short kLeftOffset    = 2;
  44. const short kTopOffset = 0;
  45.  
  46.  
  47. /* the truth is out there! */
  48.  
  49. pascal void    main(    short message, Boolean hilited, Rect *cellRect, Cell theCell,
  50.                     short dataOffset, short dataLen, ListHandle theList )
  51. {
  52.     FontInfo fontInfo;
  53.     ListPtr theListPtr;
  54.     Ptr cellData;
  55.     SignedByte hStateList, hStateCells;
  56.     Str255 str;
  57.     short leftDraw,topDraw, maxLen;
  58.     unsigned char hMode;
  59.     
  60.     /* lock and dereference list mgr handles */
  61.  
  62.     hStateList = HGetState((Handle)theList);
  63.     HLock((Handle)theList);
  64.     theListPtr = *theList;
  65.     hStateCells = HGetState((Handle)theListPtr->cells);
  66.     HLock((Handle)theListPtr->cells);
  67.     cellData = *(theListPtr->cells);
  68.     
  69.     switch (message)
  70.     {
  71.         case lInitMsg:
  72.             /* we don't need any initialization */
  73.             break;
  74.  
  75.         case lDrawMsg:
  76.             EraseRect(cellRect);
  77.         
  78.             if (dataLen > 0)
  79.             {
  80.                 /* determine starting point for drawing */
  81.  
  82.                 leftDraw = cellRect->left + theListPtr->indent.h + kLeftOffset;
  83.                 topDraw = cellRect->top + theListPtr->indent.v + kTopOffset;
  84.                 
  85.                 /* move to the text location */
  86.                 
  87.                 GetFontInfo(&fontInfo);
  88.                 MoveTo(leftDraw, topDraw + fontInfo.ascent);
  89.                 
  90.                 /* Is the cell's textwidth wider than the list's rectangle? */
  91.  
  92.                 if (TextWidth(cellData, dataOffset, dataLen) > (cellRect->right - leftDraw))
  93.                 {
  94.                     /* copy the cell's data to our string */
  95.  
  96.                     maxLen = sizeof(str);
  97.                     LGetCell(str+1, &maxLen, theCell, theList);
  98.                     *str = maxLen;
  99.                 
  100.                     /* truncate and append ellipsis to our string, then draw it */
  101.                 
  102.                     TruncString(cellRect->right - cellRect->left, str, smTruncEnd);
  103.                     DrawString(str);
  104.                 }
  105.                 else
  106.                     /* draw the cell's data */
  107.                     DrawText(cellData, dataOffset, dataLen);
  108.             }
  109.  
  110.             if (!hilited)
  111.                 break;
  112.         
  113.         case lHiliteMsg:
  114.             /* clearing the HiliteMode bit forces the next invert to really */
  115.             /* be a "hilite" mode inversion */
  116.  
  117.             hMode = LMGetHiliteMode();
  118.             BitClr((Ptr)(&hMode), (long)pHiliteBit);
  119.             LMSetHiliteMode(hMode);
  120.             InvertRect(cellRect);
  121.             break;
  122.  
  123.         case lCloseMsg:
  124.             break;
  125.     }
  126.  
  127.     /* restore the handles to their original states */
  128.  
  129.     HSetState((Handle)theListPtr->cells, hStateCells);
  130.     HSetState((Handle)theList, hStateList);
  131. }
  132.